package org.chen.auth.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import net.minidev.json.JSONUtil;
import org.chen.auth.domain.HAccount;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/ha")
public class HaController {


    public List<HAccount> upload(@RequestParam("file") MultipartFile multipartFile) throws Exception {
        //new一个模板
        ImportParams params = new ImportParams();
        //设置表格标题行数,默认0，这是读取时会跳过的行数
        params.setTitleRows(1);
        //表头行数,默认1。上午提到，如果有合并的列名，就要设置读取表头的行数
        params.setHeadRows(2);
        //开始读取，并用list接收，方便处理
        List<HAccount> result = ExcelImportUtil.importExcel(multipartFile.getInputStream(), HAccount.class, params);
        System.out.println(JSONUtil.getGetterName(String.valueOf(result)));
        return result;
    }

}
